﻿using System;
using MugenInjection.Interface;
using MugenInjection.Interface.Components;

namespace MugenInjectionTest.Components
{
    public abstract class ComponentTestBase<T> : TestBase where T : IComponent
    {
        #region Methods

        protected virtual T ConfigureComponent(IInjector injector)
        {
            return ConfigureComponent(injector, CreateNew);
        }

        protected virtual T ConfigureComponent(IInjector injector, Func<T> createNew)
        {
            T component = createNew();
            injector.Components.RemoveAll<T>();
            injector.Components.Add(component);
            return component;
        }

        protected abstract T CreateNew();

        #endregion
    }
}